<script>
import treeCom from "@/view/traffic/studentCom/treeCom.vue";
import tableMixins from "@/mixins/tableMixins.vue"
import studentCountAdd from "@/view/traffic/studentCom/studentCountAdd.vue";
import {system} from "@/util/config";

export default {
  name: "studentCount",
  mixins: [tableMixins],
  data() {
    return {
      url: "t-transportation-company-statistics",
      uploadUrl: system.apiUrl + '/t-transportation-company-statistics/import',
      token: sessionStorage.getItem("token"),
      //弹框回显
      dialogVisible: false,
      //菜单集合
      menuList: [],
      //选中
      checked: [],
      //部门树
      deptTree: null,
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      tableData: [],
      tableOption: {
        border: true,
        index: true,
        indexLabel: '序号',
        indexWidth: 50,
        stripe: true,
        align: 'center',
        addBtn: false,
        searchMenuSpan: 6,
        labelWidth: 120,
        height: '600px',
        calcHeight: 400,
        dialogWidth: 900,
        menuWidth: 200,
        menuAlign: 'center',
        editBtn: false,
        // delBtn: u.buttonPermissionsCheck("SYS_ROLE_DEL"),
        column: [
          {
            prop: 'companyStatisticsCode',
            label: 'ID',
            hide: true,
            addDisplay: false,
            editDisplay: false
          },
          {
            prop: 'year',
            label: '填报年份',
            type: 'input',
            overHidden: true,
            minWidth: 60,
            maxlength: 200,
            span: 24,
          },
          {
            prop: 'companyName',
            label: '车企名称',
            type: 'input',
            overHidden: true,
            minWidth: 60,
            maxlength: 200,
            search: true,
            span: 24,
          },
          {
            prop: 'districtName',
            label: '负责区划',
            type: 'tree',
            overHidden: true,
            minWidth: 60,
            search: true,
            maxlength: 200,
            span: 24,
            dicUrl: "/t-district/findTree",
            props: {
              label: "districtName",
              value: "districtCode",
            },
          },
          {
            prop: 'educationStage',
            label: '教育等级',
            type: 'select',
            search: true,
            overHidden: true,
            minWidth: 60,
            maxlength: 200,
            span: 24,
            dicUrl: "/common/getItem/education_level",
          },
          {
            prop: 'carNumber',
            label: '车辆数',
            type: 'input',
            overHidden: true,
            minWidth: 60,
            maxlength: 200,
            span: 24,
          },
          {
            prop: 'seatNumber',
            label: '车辆座位数',
            type: 'input',
            overHidden: true,
            minWidth: 60,
            maxlength: 200,
            span: 24,
          },
          {
            prop: 'runNumber',
            label: '每车每年趟次',
            type: 'input',
            overHidden: true,
            minWidth: 60,
            maxlength: 200,
            span: 24,
          },
          {
            prop: 'mnztc',
            label: '每年总趟次',
            type: 'input',
            overHidden: true,
            minWidth: 60,
            maxlength: 200,
            span: 24,
          },
          {
            prop: 'mnzzc',
            label: '每年总坐次',
            type: 'input',
            overHidden: true,
            minWidth: 60,
            maxlength: 200,
            span: 24,
          },
        ]
      }
    }
  },
  components: {
    treeCom: treeCom,
    studentCountAdd: studentCountAdd
  },
  methods: {
    uploadOk() {
      setTimeout(() => {
        this.getList();
      }, 1000)
    },
    down() {
      let url = system.apiUrl + '/t-transportation-company-statistics/downloadTemplate?token=' + this.token;
      window.open(url);
    }
  },
  mounted() {

  }
}
</script>

<template>
  <div class="out">
    <div class="right">
      <avue-crud :ref="ref"
                 v-model="form"
                 :page="page"
                 :data="tableData"
                 :table-loading="tableLoading"
                 :option="tableOption"
                 :before-open="beforeOpen"
                 @on-load="getList"
                 @search-change="searchChange"
                 @refresh-change="refreshChange"
                 @size-change="sizeChange"
                 @current-change="currentChange"
                 @row-update="handleUpdate"
                 @row-save="handleSave"
                 @row-del="rowDel">
        <template slot="menuLeft" slot-scope="menuLeft">
         <div style="display: flex">
           <div>
             <el-button size="small" type="primary" @click="down">下载导入模板</el-button>
           </div>
           <div>
             <el-upload class="upload-demo" :action="uploadUrl" :on-success="uploadOk"
                        :headers="{'X-Access-Token':token}">
               <el-button size="small" type="primary">导入上传车企承运数据</el-button>
             </el-upload>
           </div>
         </div>
        </template>
        <template slot="mnztc" slot-scope="scope">
          <span>{{ (scope.row.runNumber * scope.row.carNumber).toFixed(0) }}</span>
        </template>
        <template slot="mnzzc" slot-scope="scope">
          <span>{{ Math.ceil(scope.row.seatNumber * scope.row.carNumber * scope.row.runNumber) }}</span>
        </template>
      </avue-crud>
    </div>
    <student-count-add ref="studentCountAdd"></student-count-add>
  </div>
</template>

<style scoped lang="scss">
.out {
  .right {

  }
}

</style>